import QtQuick
import QtQuick.Controls
import Drillingrig
import QtQuick.Layouts
import QtQuick3D 6.2

Rectangle {
    id: screen01
    property int year
    property int month
    property int date
    property int day
    property int hour
    property int minutes
    property int second
    property int numberOfPuMpactive: 0
    width: Constants.width
    height: Constants.height
    color: Constants.backgroundColor
    function changeWorkflowView(){
        if(favorite.autoPush){
            stackLayout.currentIndex = 0;
        }
        else if(favorite.autoPull){
            stackLayout.currentIndex = 1;
        }
        else {
            stackLayout.currentIndex = 2;
        }
    }


    Timer{
        repeat: true
        running: true
        interval: 500
        onTriggered: {
            let date = new Date();
            screen01.year = date.getFullYear();
            screen01.month = date.getMonth() + 1;
            screen01.date = date.getDate();
            screen01.day = date.getDay();
            screen01.hour = date.getHours();
            screen01.minutes = date.getMinutes();
            screen01.second = date.getSeconds();
        }
    }
    FontLoader{
        id: boldFont
        source:"fonts/SourceHanSansCN-Bold.otf"
    }
    ExtensionsWindow{
        id: extensWindow
        year: screen01.year
        month: screen01.month
        day: screen01.day
        date: screen01.date
        hour: screen01.hour
        minutes: screen01.minutes
        second: screen01.second
        visible: true
        //visibility: Window.FullScreen
        SystemConfig{
            id: systemconfig02
            anchors.centerIn: parent
            modal: true
        }
    }

    SystemConfig{
        id: systemconfig01
        anchors.centerIn: parent
        modal: true
    }

    Image {
        id: image
        anchors.fill: parent
        anchors.leftMargin: 0
        anchors.rightMargin: 0
        anchors.topMargin: 0
        anchors.bottomMargin: 0
        source: "images/background-image.jpg"
        fillMode: Image.Stretch
    }

    Rectangle {
        id: timeBar
        x: 89
        y: 56
        width: 463
        height: 37
        color: "#00ffffff"

        Row {
            id: row
            anchors.fill: parent
            anchors.rightMargin: 0
            anchors.bottomMargin: 0
            spacing: 20

            Image {
                x: 0
                width: 122
                height: 37
                visible: false
                source: "images/logo.png"
                fillMode: Image.PreserveAspectFit
            }

            Rectangle {
                width: 2
                height: 24
                color: "#698c9a"
                anchors.verticalCenter: parent.verticalCenter
            }

            Text {
                id: timeShow
                width: 125
                height: 25
                color: "#ece3da"
                text: {
                    let hour = String(screen01.hour);
                    let minutes = String(screen01.minutes);
                    let second = String(screen01.second);
                    if(screen01.hour < 10){
                        hour = "0" + screen01.hour;
                    }
                    if(screen01.minutes < 10){
                        minutes = "0" + screen01.minutes;
                    }
                    if(screen01.second < 10){
                        second = "0" + screen01.second;
                    }
                    return hour + ":" + minutes + ":" + second;
                }
                anchors.verticalCenter: parent.verticalCenter
                font.pixelSize: 32
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
                font.weight: Font.Medium
            }

            Rectangle {
                width: 2
                height: 24
                color: "#698c9a"
                anchors.verticalCenter: parent.verticalCenter
            }


            Item {
                id: item1
                width: 122
                height: 37

                Column {
                    id: column
                    anchors.fill: parent
                    spacing: 6

                    Text {
                        id: weekShow
                        width: 43
                        height: 14
                        color: "#ece3da"
                        text: {
                            switch(screen01.day){
                            case 0:
                                return qsTr("星期日");
                            case 1:
                                return qsTr("星期一");
                            case 2:
                                return qsTr("星期二");
                            case 3:
                                return qsTr("星期三");
                            case 4:
                                return qsTr("星期四");
                            case 5:
                                return qsTr("星期五");
                            case 6:
                                return qsTr("星期六");
                            default:
                                return qsTr("未知");
                            }
                        }
                        font.pixelSize: 14
                        horizontalAlignment: Text.AlignLeft
                        verticalAlignment: Text.AlignTop
                        font.weight: Font.Medium
                    }

                    Text {
                        id: dateShow
                        width: 43
                        height: 14
                        color: "#ece3da"
                        text: {
                            let month = String(screen01.month);
                            let date = String(screen01.date);
                            if(month < 10){
                                month = "0" + month;
                            }
                            if(date < 10){
                                date = "0" + date;
                            }
                            return screen01.year + "-" + month + "-" + date;
                        }
                        font.pixelSize: 14
                        horizontalAlignment: Text.AlignLeft
                        verticalAlignment: Text.AlignTop
                        font.weight: Font.Medium
                    }
                }
            }
        }
    }

    Row {
        x: 1654
        y: 76
        anchors.right: parent.right
        anchors.top: parent.top
        anchors.rightMargin: 66
        anchors.topMargin: 76
        spacing: 36
        layoutDirection: Qt.RightToLeft

        IconButton {
            id: iconButton
            width: 95
            height: 20
            text: "退出登录"
            normalImage: "images/quit-normal.png"
            hoveredImage: "images/quit-hovered.png"
            onClicked: {
                Qt.quit();
            }
        }

        IconButton {
            id: systemConfigButton
            width: 95
            height: 20
            text: "系统设置"
            normalImage: "images/settings-normal.png"
            hoveredImage: "images/settings-hovered.png"
            onClicked: {
                if(!systemconfig02.visible){
                    systemconfig01.open();
                }
            }
        }

        IconButton {
            id: iconButton2
            width: 95
            height: 20
            text: "扩展屏幕"
            normalImage: "images/extended-screen-normal.png"
            hoveredImage: "images/extended-screen-hovered.png"
            onClicked: {
                let screens = Qt.application.screens;
                let index = 1;
                if(typeof(config) !== "undefined"){
                    index = config.secondScreen;
                }

                if(!extensWindow.visible){
                    extensWindow.x = screens[index].virtualX
                    extensWindow.y = screens[index].virtualY
                    extensWindow.visible = true;
                }
                else{
                    extensWindow.close();
                }
            }
        }
    }

    Rectangle {
        x: 48
        y: 112
        width: 438
        height: 42
        color: "#00ffffff"

        Image {
            id: image1
            anchors.fill: parent
            source: "images/little-title-background.png"
            fillMode: Image.PreserveAspectFit

            Text {
                id: text1
                x: 42
                y: 6
                color: "#ffffff"
                text: qsTr("状态监控")
                font.pixelSize: 20
                font.family: boldFont.name
                font.styleName: "Bold"
            }
        }
    }


    Rectangle {
        x: 48
        y: 152
        width: 438
        height: 560
        color: "#00ffffff"

        Grid {
            anchors.fill: parent
            anchors.leftMargin: 6
            anchors.rightMargin: 6
            spacing: 5
            columns: 2

            DataItem {
                valueText: (favorite.ai6 / 100).toFixed(2)
                unit: "Mpa"
                labelText: "马达压力"
            }

            DataItem {
                id: pushPressures
                valueText: (favorite.ai5 / 100).toFixed(2)
                unit: "Mpa"
                labelText: "推进压力"
            }

            DataItem {
                valueText: (favorite.ai7 / 100).toFixed(2)
                unit: "Mpa"
                labelText: "抓手夹压力"
            }

            DataItem {
                id: dataItem4
                valueText: (favorite.ai8 / 100).toFixed(2)
                unit: "Mpa"
                labelText: "抓手松压力"
            }

            DataItem {
                valueText: favorite.ai3
                unit: "mm"
                labelText: "液位传感器"
            }

            DataItem {
                valueText: favorite.ai4
                unit: "\u2103"
                labelText: "温度传感器"
            }

            DataItem {
                valueText: favorite.ai9
                unit: "mm"
                labelText: "位移"
            }

            DataItem {
                id: motorRpm1
                valueText: "0"
                unit: ""
                labelText: "备用"
            }

            DataItem {
                id: countShow
                valueText: "0"
                unit: "\u6839"
                labelText: "托钻杆数量"
            }

            DataItem {
                id: count2Show
                unit: "根"
                valueText: "0"
                labelText: "运钻杆数量"
            }


            DataItem {
                id: remCountShow
                valueText: "0"
                unit: "根"
                labelText: "钻杆箱数量"
            }

            DataItem {
                id: pushSpeedRatio
                valueText: "0.00"
                unit: "%"
                labelText: "接扣推进速度"
            }

            DataItem {
                id: preHoleDepth
                unit: "根"
                valueText: "0.00"
                labelText: "设定孔深"
            }

            DataItem {
                id: holeDepth
                valueText: "0.00"
                unit: "根"
                labelText: "当前孔深"
            }

            DataItem {
                id: motorRpm
                valueText: "0"
                unit: "%"
                labelText: "马达转速"
            }
            DataItem {
                id: fluctuationSpeed
                valueText: "0.00"
                unit: "%"
                labelText: "推进速度"
            }

            DataItem {
                id: hysteresisPressure
                valueText: "0.00"
                unit: "Mpa"
                labelText: "马达卡滞压力"
            }

            DataItem {
                id: pushHysteresisPressure
                valueText: "0.00"
                unit: "Mpa"
                labelText: "推进卡滞压力"
            }


            DataItem {
                id: havaWaterTime
                valueText: "0.00"
                unit: "s"
                labelText: "通水时间"
            }

            DataItem {
                id: uninstallTime
                valueText: "0.00"
                unit: "s"
                labelText: "反转卸扣时间"
            }







        }
    }

    Rectangle {
        x: 498
        y: 121
        width: 924
        height: 593
        color: "#00ffffff"

        Image {
            id: image2
            anchors.fill: parent
            source: "images/view3D-background.png"
            fillMode: Image.PreserveAspectFit
        }

        Rectangle {
            id: rectangle1
            width: 856
            height: 564
            color: "#00ffffff"
            anchors.centerIn: parent

            // Image {
            //     id: image3
            //     anchors.fill: parent
            //     source: "images/model-sample.png"
            //     fillMode: Image.PreserveAspectFit
            // }
            Drillingrig3D{
                id: drillingrig3D
                anchors.fill: parent
                pullDrill: favorite.autoPull
                pushDrill: favorite.autoPush
            }
        }
    }

    Rectangle {
        x: 56
        y: 112
        width: 438
        height: 42
        color: "#00ffffff"
        anchors.right: parent.right
        anchors.rightMargin: 48
        Image {
            id: image4
            anchors.fill: parent
            source: "images/little-title-background.png"
            fillMode: Image.PreserveAspectFit
            Text {
                id: text2
                x: 42
                y: 6
                color: "#ffffff"
                text: qsTr("工作状态")
                font.pixelSize: 20
                font.styleName: "Bold"
                font.family: boldFont.name
            }
        }
    }

    Rectangle {
        x: 1434
        y: 152
        width: 438
        height: 268
        color: "#00ffffff"
        Grid {
            anchors.fill: parent
            spacing: 5
            columns: 2

            StateItem {
                id: stateItem
                valueText: "本地"
                labelText: "控制模式"
            }

            StateItem {
                id: stateItem1
                valueText: favorite.do12 ? "开启": "关闭"
                labelText: "逆水阀"
            }

            StateItem {
                id: stateItem2
                valueText: "开启"
                labelText: "启动权限"
            }

            StateItem {
                valueText: {
                    if(favorite.isStarted){
                        return qsTr("开始");
                    }
                    else if (favorite.isPaused){
                        return qsTr("暂停");
                    }
                    else if (favorite.isStopped){
                        return qsTr("停止");
                    }
                    else {
                        return qsTr("无");
                    }
                }
                labelText: "运行状态"
            }


            StateItem {
                id: stateItem6
                valueText: {
                    if(favorite.autoPush){
                        return qsTr("自动打钻");
                    }
                    else if(favorite.autoPull){
                        return qsTr("自动卸钻");
                    }
                    else{
                        return qsTr("手动");
                    }
                }

                labelText: "工作权限"
            }

            StateItem {
                id: stateItem7
                textColor: interaction.isConnected ? "#0ef1fa" : "#dc1297"
                valueText: interaction.isConnected ? qsTr("已连接"):qsTr("已断开")
                labelText: "通讯"
            }

            StateItem {
                id: stateItem3
                valueText: "关闭"
                labelText: "备用"
            }
            StateItem {
                id: stateItem5
                valueText: "0"
                labelText: "备用"
            }
        }
    }

    Rectangle {
        x: 51
        y: 410
        width: 438
        height: 42
        color: "#00ffffff"
        anchors.right: parent.right
        anchors.rightMargin: 48
        Image {
            id: image5
            anchors.fill: parent
            source: "images/little-title-background.png"
            fillMode: Image.PreserveAspectFit
            Text {
                id: text3
                x: 42
                y: 6
                color: "#ffffff"
                text: qsTr("油泵参数")
                font.pixelSize: 20
                font.styleName: "Bold"
                font.family: boldFont.name
            }
        }
    }

    Rectangle {
        x: 1437
        y: 450
        width: 438
        height: 252
        color: "#00ffffff"
        Grid {
            anchors.fill: parent
            anchors.leftMargin: 0
            anchors.rightMargin: 6
            spacing: 5
            columns: 2

            DataItem {
                id: dataItem28
                height: 48
                valueText: favorite.pumpRunning ? "运行":"关闭"
                unit: ""
                labelText: "油泵状态"
            }


            DataItem {
                id: dataItem36
                height: 48
                valueText: screen01.numberOfPuMpactive
                unit: "\u6b21"
                labelText: "启动次数"
            }

            DataItem {
                id: dataItem34
                height: 48
                valueText: favorite.ai3
                labelText: "液位"
                unit: "mm"
            }

            DataItem {
                id: oilProtected
                height: 48
                valueText: "无保护"
                unit: ""
                labelText: "油位保护"
            }

            DataItem {
                id: dataItem32
                height: 48
                valueText: favorite.ai4
                unit: "\u2103"
                labelText: "油温"
            }

            DataItem {
                id: oilProtected2
                height: 48
                valueText: "无保护"
                unit: ""
                labelText: "油温保护"
            }


            DataItem {
                id: sysVoltage
                height: 48
                valueText: "0"
                unit: "V"
                labelText: "系统电压"
            }

            DataItem {
                id: dataItem31
                height: 48
                valueText: (elapsedObj.currentCumHour / 1000 / 60 / 60).toFixed(2)
                unit: "h"
                labelText: "本次电机时长"
            }


            DataItem {
                id: dataItem33
                height: 48
                valueText: (elapsedObj.cumulativeHour / 1000 / 60 / 60).toFixed(2)
                unit: "h"
                labelText: "电机运行时长"
            }
            DataItem {
                id: dataItem37
                height: 48
                valueText: "0"
                unit: ""
                labelText: "备用"
            }
        }
    }

    Rectangle {
        id: tableBar
        x: 41
        y: 730
        width: 1830
        height: 40
        color: "#00ffffff"

        Image {
            id: image6
            anchors.fill: parent
            source: "images/long-title-background.png"
            fillMode: Image.PreserveAspectFit
        }
        ButtonGroup{
            buttons: row5.children
        }

        Row {
            id: row5
            anchors.fill: parent
            anchors.leftMargin: 50
            spacing: -20

            TabbarButton {
                id: tabbarButton
                x: 44
                y: -5
                text: "自动打钻"
                checked: stackLayout.currentIndex === 0
                checkable: true
                onClicked: {
                    stackLayout.currentIndex = 0;
                }
            }

            TabbarButton {
                id: tabbarButton1
                x: 167
                y: -4
                text: "自动卸钻"
                checked: stackLayout.currentIndex === 1
                checkable: true
                onClicked: {
                    stackLayout.currentIndex = 1;
                }
            }

            TabbarButton {
                id: tabbarButton2
                x: 295
                y: -4
                text: "动作状态"
                checked: stackLayout.currentIndex === 2
                checkable: true
                onClicked: {
                    stackLayout.currentIndex = 2;
                }
            }
        }
    }

    Rectangle {
        x: 8
        y: 8
        color: "#00ffffff"
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.top: tableBar.bottom
        anchors.bottom: parent.bottom
        anchors.leftMargin: 48
        anchors.rightMargin: 48
        anchors.topMargin: 9
        anchors.bottomMargin: 48

        StackLayout {
            id: stackLayout
            anchors.fill: parent
            clip: true
            currentIndex: changeWorkflowView()
            PushWorkflow{
            }
            PullWorkflow{
            }
            ActionsWorkflow{
            }
        }
    }
    Timer{
        id: elasedTimer
        running: false
        repeat: true
        interval: 1000
        onTriggered: {
            elapsedObj.cumulativeHour += interval;
            elapsedObj.currentCumHour += interval;
        }
    }
    QtObject{
        id: elapsedObj
        property real cumulativeHour : 0
        property real currentCumHour: 0

    }

    Connections{
        target: favorite
        function onAutoPushChanged(){
            changeWorkflowView();
        }
        function onAutoPullChanged(){
            changeWorkflowView();
        }
        function onPumpRunningChanged(){
            if(favorite.pumpRunning){
                elasedTimer.running = true;
                screen01.numberOfPuMpactive++;
            }
            else{
                elasedTimer.running = false;
                elapsedObj.currentCumHour = 0;
            }
        }
    }

    Connections{
        target: attributes
        function onRegisterUpdated(address:int, bit:int, bv:bool){
            switch(address){
            case 1:
                switch(bit){
                case 0:
                    if(bv){
                        stackLayout.currentIndex = 0;
                        drillingrig3D.pushDrill = true;
                        drillingrig3D.pullDrill = false;
                    }
                    else if(!favorite.autoPush && !favorite.autoPull){
                        stackLayout.currentIndex = 2;
                        drillingrig3D.pullDrill = false;
                        drillingrig3D.pushDrill = false;
                    }
                    break;
                case 1:
                    if(bv){
                        stackLayout.currentIndex = 1;
                        drillingrig3D.pushDrill = false;
                        drillingrig3D.pullDrill = true;
                    }
                    else if(!favorite.autoPush && !favorite.autoPull){
                        stackLayout.currentIndex = 2;
                        drillingrig3D.pullDrill = false;
                        drillingrig3D.pushDrill = false;
                    }
                    break;
                case 9:
                case 10:
                    if(bv){
                        stackLayout.currentIndex = 1;
                        drillingrig3D.pullDrill = true;
                        drillingrig3D.pushDrill = false;
                    }
                    else{
                        if(favorite.autoPush){
                            stackLayout.currentIndex = 0;
                            drillingrig3D.pullDrill = false;
                            drillingrig3D.pushDrill = true;
                        }
                        else if(favorite.autoPull){
                            stackLayout.currentIndex = 1;
                            drillingrig3D.pullDrill = true;
                            drillingrig3D.pushDrill = false;
                        }
                        else{
                            stackLayout.currentIndex = 2;
                            drillingrig3D.pullDrill = false;
                            drillingrig3D.pushDrill = false;
                        }
                    }

                    break;
                }
                break;
            case 66:
                switch(bit){
                case 7:
                    if(bv){
                        interaction.logReport(qsTr("远程切换"), 0);
                        stateItem.valueText = qsTr("远程");
                    }
                    else{
                        stateItem.valueText = qsTr("本地");
                        interaction.logReport("本地切换", 0);
                    }
                    break;
                default:
                    break;
                }
                break;
            case 67:
                countShow.valueText = attributes.values["67"];
                break;
            case 68:
                holeDepth.valueText = attributes.values["68"];
                break;
            case 69:
                preHoleDepth.valueText = attributes.values["69"];
                break;
            case 76:
                remCountShow.valueText = attributes.values["76"];
                break;
            case 77:
                if(bv){
                    switch(bit){
                    case 0:
                        interaction.logReport(qsTr("MU2掉线"), 1);
                        break;
                    case 1:
                        interaction.logReport(qsTr("MU2控制"), 0);
                        break;
                    case 2:
                        interaction.logReport(qsTr("油位过低"), 1);
                        break;
                    default:
                        break;
                    }
                }
                break;
            case 78:
                if(attributes.values["78"]){
                    interaction.logReport(qsTr("急停按下"), 2);
                }
                else {
                    interaction.logReport(qsTr("急停弹起"), 0);
                }
                break;
            case 79:
                count2Show.valueText = attributes.values["79"];
                break;
            case 80:
                hysteresisPressure.valueText = (attributes.values["80"] / 100).toFixed(2);
                break;
            case 81:
                pushHysteresisPressure.valueText = (attributes.values["81"] / 100).toFixed(2);
                break;
            case 82:
                motorRpm.valueText = attributes.values["82"];
                break;
            case 83:
                fluctuationSpeed.valueText = attributes.values["83"];
                break;
            case 84:
                havaWaterTime.valueText = (attributes.values["84"] / 10).toFixed(1);
                break;
            case 85:
                uninstallTime.valueText = (attributes.values["85"] / 10).toFixed(1);
                break;
            case 86:
                pushSpeedRatio.valueText = (attributes.values["86"]).toFixed(0);
                break;
            case 90:
                if(bv){
                    switch(bit){
                    case 0:
                        interaction.logReport(qsTr("配置文件错误"), 2);
                        break;
                    case 1:
                        interaction.logReport(qsTr("自动打钻油温低"), 1);
                        break;
                    case 2:
                        interaction.logReport(qsTr("油温过高"), 2);
                        break;
                    case 3:
                        interaction.logReport(qsTr("编码器掉线"), 1);
                        break;
                    case 4:
                        interaction.logReport(qsTr("PLC掉线"), 1);
                        break;
                    case 5:
                        interaction.logReport(qsTr("电机未启动"), 2);
                        break;
                    case 6:
                        interaction.logReport(qsTr("推进位移掉线"), 1);
                        break;
                    }
                }
                break;
            case 91:
                if(bv){
                    switch(bit){
                    case 0:
                        interaction.logReport(qsTr("抓手到机架检测错误"), 2);
                        break;
                    case 1:
                        interaction.logReport(qsTr("抓臂伸错误"), 2);
                        break;
                    case 2:
                        interaction.logReport(qsTr("抓臂缩错误"), 2);
                        break;
                    case 3:
                        interaction.logReport(qsTr("钻杆左移错误"), 2);
                        break;
                    case 4:
                        interaction.logReport(qsTr("钻杆右移错误"), 2);
                        break;
                    case 5:
                        interaction.logReport(qsTr("托钻杆升错误"), 2);
                        break;
                    case 6:
                        interaction.logReport(qsTr("最前杆检测错误"), 2);
                        break;
                    case 7:
                        interaction.logReport(qsTr("最后杆检测错误"), 2);
                        break;
                    case 8:
                        interaction.logReport(qsTr("钻框升错误"), 2);
                        break;
                    case 9:
                        interaction.logReport(qsTr("钻框降错误"), 2);
                        break;
                    case 10:
                        interaction.logReport(qsTr("钻框顶错误"), 2);
                        break;
                    case 11:
                        interaction.logReport(qsTr("钻框底错误"), 2);
                        break;
                    case 12:
                        interaction.logReport(qsTr("退钻卸后扣位置错误"), 2);
                        break;
                    case 13:
                        interaction.logReport(qsTr("托钻杆下降检测错误"), 2);
                        break;
                    default:
                        break;
                    }
                }
                break;
            case 92:
                if(bv){
                    switch(bit){
                    case 0:
                        interaction.logReport(qsTr("打钻最前卸掉扣位置错误"), 2);
                        break;
                    case 1:
                        interaction.logReport(qsTr("动力头最后位置错误"), 2);
                        break;
                    case 2:
                        interaction.logReport(qsTr("打钻接后扣错误"), 2);
                        break;
                    case 3:
                        interaction.logReport(qsTr("打钻接前扣错误"), 2);
                        break;
                    case 4:
                        interaction.logReport(qsTr("退钻卸前扣位置错误"), 2);
                        break;
                    case 5:
                        interaction.logReport(qsTr("退钻卸掉前扣位置错误"), 2);
                        break;
                    case 6:
                        interaction.logReport(qsTr("退钻接扣错误"), 2);
                        break;
                    default:
                        break;
                    }
                }
                break;
            case 93:
                if(bv){
                    switch(bit){
                    case 0:
                        interaction.logReport(qsTr("抓手正负旋错误"), 2);
                        break;
                    case 1:
                        interaction.logReport(qsTr("编码器1故障"), 2);
                        break;
                    case 2:
                        interaction.logReport(qsTr("编码器2故障"), 2);
                        break;
                    case 3:
                        interaction.logReport(qsTr("编码器3故障"), 2);
                        break;
                    case 4:
                        interaction.logReport(qsTr("托钻杆数量错误"), 1);
                        break;
                    case 5:
                        interaction.logReport(qsTr("抓手夹错误"), 2);
                        break;
                    case 6:
                        interaction.logReport(qsTr("抓手松错误"), 2);
                        break;
                    case 7:
                        interaction.logReport(qsTr("钻框满"), 1);
                        break;
                    case 8:
                        interaction.logReport(qsTr("钻框空"), 1);
                        break;
                    case 9:
                        interaction.logReport(qsTr("打钻卡滞"), 1);
                        break;
                    case 10:
                        interaction.logReport(qsTr("自动扫孔"), 0);
                        break;
                    default:
                        break;
                    }
                }
                break;
            case 96:
                if(attributes.values["96"]){
                    oilProtected2.valueText = attributes.values["96"];
                    oilProtected2.unit = "℃";
                }
                else{
                    oilProtected2.valueText = qsTr("无保护");
                    oilProtected2.unit = "";
                }

                break;
            case 97:
                if(attributes.values["97"]){
                    oilProtected.valueText = attributes.values["97"];
                    oilProtected.unit = "mm";
                }
                else{
                    oilProtected.valueText = qsTr("无保护");
                    oilProtected.unit = "";
                }
                break;
            case 100:
                switch(attributes.values["100"]){
                case 0:
                    drillingrig3D.playBracketOpen();
                    break;
                case 1:
                    drillingrig3D.playDrillBoxUp();
                    break;
                case 2:
                    drillingrig3D.playBracketClose();
                    break;
                case 3:
                    drillingrig3D.playDrillBoxUp();
                    break;
                case 4:
                    drillingrig3D.playDrillBoxDown();
                    break;
                }
                break;
            case 101:
                switch(attributes.values["101"]){
                case 4:
                    drillingrig3D.canTakeDrill = true;
                    drillingrig3D.playMdot6Right();
                    break;
                case 6:
                    drillingrig3D.canTakeDrill = false;
                    drillingrig3D.playMdot6Left();
                    break;
                }
                break;
            case 102:
                switch(attributes.values["102"]){
                case 0:
                    drillingrig3D.resetMdot7();
                    drillingrig3D.resetMdot3();
                    break;
                case 2:
                    drillingrig3D.startMdot7();
                    break;
                case 4:
                    drillingrig3D.takedDrill = true;
                    break;
                case 7:
                    drillingrig3D.startMdot3();
                    break;
                case 11:
                    drillingrig3D.playBacktongsClose();
                    break;
                case 12:
                    drillingrig3D.dropDrill = true;
                    drillingrig3D.takedDrill = false;
                    break;
                case 13:
                    break;
                }
                break;
            case 103:
                switch(attributes.values["103"]){
                case 1:
                    // drillingrig3D.headDrill = true;
                    // drillingrig3D.dropDrill = false;
                    drillingrig3D.playFronttongsClose();
                    break;
                case 2:
                    //drillingrig3D.calibrateMg3();
                    drillingrig3D.dropDrill = false;
                    break;
                case 6:
                    drillingrig3D.playBacktongsOpen();
                    break;
                case 8:
                    drillingrig3D.playFronttongsOpen();
                    break;
                }
                break;
            case 104:
                switch(attributes.values["104"]){
                case 0:
                    drillingrig3D.playDrillBoxDown();
                    break;
                case 1:
                    drillingrig3D.playBracketOpen();
                    break;
                case 2:
                    drillingrig3D.playDrillBoxDown();
                    break;
                case 3:
                    drillingrig3D.playBracketClose();
                    break;
                case 4:
                    drillingrig3D.playDrillBoxUp();
                    break;
                }
                break;
            case 105:
                switch(attributes.values["105"]){
                case 1:
                    drillingrig3D.playMdot6Left();
                    break;
                case 4:
                    drillingrig3D.canTakeDrill = false;
                    break;
                case 6:
                   drillingrig3D.playMdot6Right();
                   break;
                }
                break;
            case 106:
                switch(attributes.values["106"]){
                case 0:
                    drillingrig3D.resetMdot3();
                    break;
                case 2:
                    drillingrig3D.takedDrill = false;
                    drillingrig3D.canTakeDrill = true;
                    break;
                case 4:
                    drillingrig3D.resetMdot7();
                    break;
                case 6:
                    drillingrig3D.startMdot7();
                    drillingrig3D.startMdot3();
                    break;
                case 9:
                    drillingrig3D.takedDrill = true;
                    drillingrig3D.headDrill = true;
                    drillingrig3D.dropDrill = false;
                    break;
                case 10:
                    drillingrig3D.takedDrill = true;
                    drillingrig3D.headDrill = true
                    drillingrig3D.dropDrill = false;
                    drillingrig3D.playBacktongsOpen();
                    break;
                }
                break;
            case 107:
                switch(attributes.values["107"]){
                case 1:
                    drillingrig3D.playFronttongsClose();
                    drillingrig3D.playBacktongsClose();
                    break;
                case 3:
                    drillingrig3D.playBacktongsOpen();
                    break;
                case 7:
                    drillingrig3D.playBacktongsClose();
                    break;
                case 12:
                    drillingrig3D.dropDrill = true;
                    drillingrig3D.playFronttongsOpen();
                    break;
                }
                break;
            case 150:
                sysVoltage.valueText = attributes.values["150"];
                break;
            default:
                break;
            }
        }
    }
    Item {
        id: __materialLibrary__
    }
}

